package com.ada.tft_sport.fragment;

import com.ada.tft_sport.R;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

public class SchemaFragment extends Fragment {

	private View schemaFragment; // 主界面

	private FragmentManager fManager; // 碎片管理器
	private FragmentTransaction fTransaction; // 获取事务处理对象

	private TextView et_time, et_weight, et_age, et_edit;
    private TextView show_text_schema,show_num_schema;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// 每次切换此页面时，不需要重新创建Fragment对象
		setRetainInstance(true);
	}

	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

		// 实例化布局文件
		schemaFragment = inflater.inflate(R.layout.fragment_schema, container,
				false);
		et_time = (TextView) schemaFragment.findViewById(R.id.et_time);
		et_weight = (TextView) schemaFragment.findViewById(R.id.et_weight);
		et_age = (TextView) schemaFragment.findViewById(R.id.et_age);
		show_text_schema=(TextView)schemaFragment.findViewById(R.id.show_text_schema);
		show_num_schema=(TextView)schemaFragment.findViewById(R.id.show_num_schema);
		
		et_edit = show_num_schema;
		show_text_schema.setText(et_time.getText());

		et_time.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				show_text_schema.setText(et_time.getText());
				show_num_schema.setText(null);

			}
		});
		et_weight.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				show_text_schema.setText(et_weight.getText());
				show_num_schema.setText(null);

			}
		});

		et_age.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String age= show_num_schema.getText().toString();
				show_text_schema.setText(et_age.getText());
				show_num_schema.setText(null);

			}
		});
		TextView one = (TextView) schemaFragment.findViewById(R.id.one);
		TextView two = (TextView) schemaFragment.findViewById(R.id.two);
		TextView three = (TextView) schemaFragment.findViewById(R.id.three);
		TextView four = (TextView) schemaFragment.findViewById(R.id.four);
		TextView five = (TextView) schemaFragment.findViewById(R.id.five);
		TextView six = (TextView) schemaFragment.findViewById(R.id.six);
		TextView seven = (TextView) schemaFragment.findViewById(R.id.seven);
		TextView eight = (TextView) schemaFragment.findViewById(R.id.eight);
		TextView night = (TextView) schemaFragment.findViewById(R.id.night);
		TextView zero = (TextView) schemaFragment.findViewById(R.id.zero);
		TextView delete = (TextView) schemaFragment.findViewById(R.id.delete);
		TextView enter = (TextView) schemaFragment.findViewById(R.id.enter);

		one.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub

				String i = et_edit.getText().toString().trim();
				et_edit.setText(i + 1);
			}
		});
		two.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = et_edit.getText().toString().trim();
				et_edit.setText(i + 2);
			}
		});
		three.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = et_edit.getText().toString().trim();
				et_edit.setText(i + 3);
			}
		});
		four.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = et_edit.getText().toString().trim();
				et_edit.setText(i + 4);
			}
		});
		five.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = et_edit.getText().toString().trim();
				et_edit.setText(i + 5);
			}
		});
		six.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = et_edit.getText().toString().trim();
				et_edit.setText(i + 6);
			}
		});
		seven.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = (String) et_edit.getText().toString().trim();
				et_edit.setText(i + 7);
			}
		});
		eight.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = et_edit.getText().toString().trim();
				et_edit.setText(i + 8);
			}
		});
		night.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = (String) et_edit.getText().toString().trim();
				et_edit.setText(i + 9);
			}
		});
		zero.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				String i = (String) et_edit.getText().toString().trim();
				et_edit.setText(i + 0);
			}
		});
		delete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				et_edit.setText("");
			}
		});
		enter.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub

			}
		});

		fManager = getActivity().getSupportFragmentManager(); // 获得碎片管理器
		fTransaction = fManager.beginTransaction(); // 获取事务处理对象

		return schemaFragment; // 返回视图对象

	}

}
